﻿@model IEnumerable<bsuc.common.Model.Bsuc_Menu>
@{
    ViewBag.Title = "菜单添加";
}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>菜单添加</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="PostAdd" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-inline">
            <input type="text" name="title" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">URL</label>
        <div class="layui-input-inline">
            <input type="text" name="url" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">模块/控制器名/方法名 如：admin/home/index</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">父级菜单</label>
        <div class="layui-input-inline">
            <select name="parent_id" lay-filter="aihao">
                <option value="" selected=""></option>
                <option value="0">作为顶级菜单</option>
                @foreach (var item in Model)
                {
                    <option value="@Html.DisplayFor(m => item.id)">@Html.DisplayFor(m => item.title)</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="text" name="sort" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">0~999 默认：999</div>
    </div>
        <div class="layui-form-item">
        <label class="layui-form-label">系统菜单</label>
        <div class="layui-input-inline">
            <input type="radio" class="field-system" name="system" value="1" title="是">
            <input type="radio" class="field-system" name="system" value="0" title="否" checked>
        </div>
        <div class="layui-form-mid layui-word-aux">
            设置为系统菜单后，无法删除
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="radio" name="nav" value="0" title="不显示">
            <input type="radio" name="nav" value="1" title="显示" checked="">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">菜单状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="禁用">
            <input type="radio" name="status" value="1" title="启用" checked="">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="menuadd">提交</button>
    </div>
</form>
<script type="text/javascript">
    layui.define('form', function (exports) {
        var $ = layui.jquery, layer = layui.layer, form = layui.form;
        form.on('submit(menuadd)', function (data) {
            var _form = $(this).parents('form');
            layer.msg('数据提交中...', { time: 500000 });
            $.ajax({
                type: "POST",
                url: _form.attr('action'),
                dataType: 'json',
                data: _form.serialize(),
                success: function (res) {
                    console.log(res);
                    layer.msg(res.msg, {}, function () {
                        if (res.code == 1) {
                            if (typeof (res.url) != 'undefined' && res.url != null && res.url != '') {
                                location.href = res.url;
                            } else {
                                location.reload();
                            }
                        } else {
                            location.reload();
                        }
                    });
                }
            });
            return false;
        });
    });
</script>
